﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Utilities;
using System.Web.UI.MobileControls;

namespace SPArtistic.Layouts.MobileApproval
{
    public partial class MyTasks : System.Web.UI.MobileControls.MobilePage
    {
        private string taskListName = "任务";
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Label1.Text = SPEncode.HtmlEncode("我的任务列表");
            this.ViewTask.Text = SPEncode.HtmlEncode("审批");

        }
        protected override void OnInit(EventArgs e)
        {
            getTask();
            base.OnInit(e);
        }
        private void getTask()
        {
            SPWeb mWeb = SPContext.Current.Web;
            SPList mTaskList = mWeb.Lists[taskListName];
            string queryString = "<Where><And><Eq><FieldRef Name='AssignedTo' /><Value Type='User'>" + mWeb.CurrentUser.Name + "</Value></Eq>" +
                "<Neq><FieldRef Name='PercentComplete' /><Value Type='Number'>1</Value></Neq></And></Where>" +
                "<OrderBy><FieldRef Name='StartDate' Ascending='False' /></OrderBy>";
            SPQuery myQuery = new SPQuery();
            myQuery.Query = queryString;
            SPListItemCollection myTasks = mTaskList.GetItems(myQuery);
            foreach (SPListItem mTaskItem in myTasks)
            {
                this.myApproveTask.Items.Add(new MobileListItem(mTaskItem.Title, mTaskItem.UniqueId.ToString()));
            }
            mWeb.Close();
        }
        protected void ViewTask_Click(object sender, EventArgs e)
        {
            if (this.myApproveTask.SelectedIndex >= 0)
                Response.Redirect("Approval.aspx?TaskID=" + this.myApproveTask.Items[this.myApproveTask.SelectedIndex].Value);
        }
    }
}
